//
// CShapeBank.java
// Copyright (C) 2010  "Naush" <naush _ hotmail _ fr>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>./* ----------------------------------------------------------------------------







package org.ryzom.nel.threed;

import org.ryzom.nel.misc.CVector;

public class CShapeBank {
  private long swigCPtr;
  protected boolean swigCMemOwn;

  public CShapeBank(long cPtr, boolean cMemoryOwn) {
    swigCMemOwn = cMemoryOwn;
    swigCPtr = cPtr;
  }

  public static long getCPtr(CShapeBank obj) {
    return (obj == null) ? 0 : obj.swigCPtr;
  }

  protected void finalize() {
    delete();
  }

  public synchronized void delete() {
    if (swigCPtr != 0) {
      if (swigCMemOwn) {
        swigCMemOwn = false;
        nel3dJNI.delete_CShapeBank(swigCPtr);
      }
      swigCPtr = 0;
    }
  }

  public CShapeBank() {
    this(nel3dJNI.new_CShapeBank(), true);
  }

  public IShape addRef(String shapeName) {
    long cPtr = nel3dJNI.CShapeBank_addRef(swigCPtr, this, shapeName);
    return (cPtr == 0) ? null : new IShape(cPtr, false);
  }

  public void release(IShape pShp) {
    nel3dJNI.CShapeBank_release(swigCPtr, this, IShape.getCPtr(pShp), pShp);
  }

  public CShapeBank.TShapeState getPresentState(String shapeName) {
    return CShapeBank.TShapeState.swigToEnum(nel3dJNI.CShapeBank_getPresentState(swigCPtr, this, shapeName));
  }

  public IShape getShape(String shapeName) {
    long cPtr = nel3dJNI.CShapeBank_getShape(swigCPtr, this, shapeName);
    return (cPtr == 0) ? null : new IShape(cPtr, false);
  }

  public void load(String shapeName) {
    nel3dJNI.CShapeBank_load(swigCPtr, this, shapeName);
  }

  public void loadAsync(String shapeName, IDriver pDriver, CVector position, SWIGTYPE_p_bool bSignal, long selectedTexture) {
    nel3dJNI.CShapeBank_loadAsync(swigCPtr, this, shapeName, IDriver.getCPtr(pDriver), pDriver, CVector.getCPtr(position), position, SWIGTYPE_p_bool.getCPtr(bSignal), selectedTexture);
  }

  public void cancelLoadAsync(String shapeName) {
    nel3dJNI.CShapeBank_cancelLoadAsync(swigCPtr, this, shapeName);
  }

  public boolean isShapeWaiting() {
    return nel3dJNI.CShapeBank_isShapeWaiting(swigCPtr, this);
  }

  public void processWaitingShapes() {
    nel3dJNI.CShapeBank_processWaitingShapes(swigCPtr, this);
  }

  public void setMaxBytesToUpload(long MaxUploadPerFrame) {
    nel3dJNI.CShapeBank_setMaxBytesToUpload(swigCPtr, this, MaxUploadPerFrame);
  }

  public void add(String shapeName, IShape shape) {
    nel3dJNI.CShapeBank_add(swigCPtr, this, shapeName, IShape.getCPtr(shape), shape);
  }

  public void addShapeCache(String shapeCacheName) {
    nel3dJNI.CShapeBank_addShapeCache(swigCPtr, this, shapeCacheName);
  }

  public void removeShapeCache(String shapeCacheName) {
    nel3dJNI.CShapeBank_removeShapeCache(swigCPtr, this, shapeCacheName);
  }

  public boolean isShapeCache(String shapeCacheName) {
    return nel3dJNI.CShapeBank_isShapeCache(swigCPtr, this, shapeCacheName);
  }

  public void reset() {
    nel3dJNI.CShapeBank_reset(swigCPtr, this);
  }

  public void setShapeCacheSize(String shapeCacheName, int maxSize) {
    nel3dJNI.CShapeBank_setShapeCacheSize(swigCPtr, this, shapeCacheName, maxSize);
  }

  public int getShapeCacheFreeSpace(String shapeCacheName) {
    return nel3dJNI.CShapeBank_getShapeCacheFreeSpace(swigCPtr, this, shapeCacheName);
  }

  public void linkShapeToShapeCache(String shapeName, String shapeCacheName) {
    nel3dJNI.CShapeBank_linkShapeToShapeCache(swigCPtr, this, shapeName, shapeCacheName);
  }

  public void preLoadShapes(String shapeCacheName, Vector_String listFile, String wildCardNotLwr, SWIGTYPE_p_NLMISC__IProgressCallback progress, boolean flushTextures, IDriver drv) {
    nel3dJNI.CShapeBank_preLoadShapes__SWIG_0(swigCPtr, this, shapeCacheName, Vector_String.getCPtr(listFile), listFile, wildCardNotLwr, SWIGTYPE_p_NLMISC__IProgressCallback.getCPtr(progress), flushTextures, IDriver.getCPtr(drv), drv);
  }

  public void preLoadShapes(String shapeCacheName, Vector_String listFile, String wildCardNotLwr, SWIGTYPE_p_NLMISC__IProgressCallback progress, boolean flushTextures) {
    nel3dJNI.CShapeBank_preLoadShapes__SWIG_1(swigCPtr, this, shapeCacheName, Vector_String.getCPtr(listFile), listFile, wildCardNotLwr, SWIGTYPE_p_NLMISC__IProgressCallback.getCPtr(progress), flushTextures);
  }

  public void preLoadShapes(String shapeCacheName, Vector_String listFile, String wildCardNotLwr, SWIGTYPE_p_NLMISC__IProgressCallback progress) {
    nel3dJNI.CShapeBank_preLoadShapes__SWIG_2(swigCPtr, this, shapeCacheName, Vector_String.getCPtr(listFile), listFile, wildCardNotLwr, SWIGTYPE_p_NLMISC__IProgressCallback.getCPtr(progress));
  }

  public void preLoadShapes(String shapeCacheName, Vector_String listFile, String wildCardNotLwr) {
    nel3dJNI.CShapeBank_preLoadShapes__SWIG_3(swigCPtr, this, shapeCacheName, Vector_String.getCPtr(listFile), listFile, wildCardNotLwr);
  }

  public void buildSystemGeometryForshape(String shapeName) {
    nel3dJNI.CShapeBank_buildSystemGeometryForshape(swigCPtr, this, shapeName);
  }

  public SWIGTYPE_p_std__string getShapeNameFromShapePtr(IShape pShp) {
    long cPtr = nel3dJNI.CShapeBank_getShapeNameFromShapePtr(swigCPtr, this, IShape.getCPtr(pShp), pShp);
    return (cPtr == 0) ? null : new SWIGTYPE_p_std__string(cPtr, false);
  }

  public final static class TShapeState {
    public final static TShapeState NotPresent = new TShapeState("NotPresent");
    public final static TShapeState Present = new TShapeState("Present");
    public final static TShapeState AsyncLoad_Error = new TShapeState("AsyncLoad_Error");
    public final static TShapeState AsyncLoad_Shape = new TShapeState("AsyncLoad_Shape");
    public final static TShapeState AsyncLoad_Texture = new TShapeState("AsyncLoad_Texture");
    public final static TShapeState AsyncLoad_Ready = new TShapeState("AsyncLoad_Ready");
    public final static TShapeState AsyncLoad_Delete = new TShapeState("AsyncLoad_Delete");

    public final int swigValue() {
      return swigValue;
    }

    public String toString() {
      return swigName;
    }

    public static TShapeState swigToEnum(int swigValue) {
      if (swigValue < swigValues.length && swigValue >= 0 && swigValues[swigValue].swigValue == swigValue)
        return swigValues[swigValue];
      for (int i = 0; i < swigValues.length; i++)
        if (swigValues[i].swigValue == swigValue)
          return swigValues[i];
      throw new IllegalArgumentException("No enum " + TShapeState.class + " with value " + swigValue);
    }

    private TShapeState(String swigName) {
      this.swigName = swigName;
      this.swigValue = swigNext++;
    }

    private TShapeState(String swigName, int swigValue) {
      this.swigName = swigName;
      this.swigValue = swigValue;
      swigNext = swigValue+1;
    }

    private TShapeState(String swigName, TShapeState swigEnum) {
      this.swigName = swigName;
      this.swigValue = swigEnum.swigValue;
      swigNext = this.swigValue+1;
    }

    private static TShapeState[] swigValues = { NotPresent, Present, AsyncLoad_Error, AsyncLoad_Shape, AsyncLoad_Texture, AsyncLoad_Ready, AsyncLoad_Delete };
    private static int swigNext = 0;
    private final int swigValue;
    private final String swigName;
  }

}
